﻿// -----------------------------------------------------------------------
// <copyright file="ConfigCollectionExtensions.cs" company="EPAM Systems">
////Copyright (c) EPAM Systems, 2012. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace MBOP.Configuration.ConfigExtensions
{
	#region Usings

	using System;
	using System.Collections.Generic;
	using System.Configuration;

	using MBOP.Configuration.ConfigElements;

	#endregion

	/// <summary>
	/// Provides extension methods for configuration element collection.
	/// </summary>
	public static class ConfigCollectionExtensions
	{
		/// <summary>
		/// Checks the specified condition complete for each element or not.
		/// </summary>
		/// <param name="elementCollection">The current element collection.</param>
		/// <param name="condition">The specified condition.</param>
		/// <returns>Value indicates that the condition complete or not.</returns>
		public static bool IsConditionComplete(this ConfigurationElementCollection elementCollection, Func<int, bool> condition)
		{
			bool isComplete = false;

			for (int index = 0; index < elementCollection.Count; index++)
			{
				if (condition(index))
				{
					isComplete = true;
					break;
				}
			}

			return isComplete;
		}

		/// <summary>
		/// Gets the admin tokens
		/// </summary>
		/// <param name="elementCollection">The admin element collection.</param>
		/// <returns>The collection of tokens.</returns>
		public static IEnumerable<string> GetTokens(this AdminElementCollection elementCollection)
		{
			List<string> tokens = new List<string>();

			for (int index = 0; index < elementCollection.Count; index++)
			{
				tokens.Add(elementCollection[index].Token);
			}

			return tokens;
		}
	}
}
